<?php

namespace App\Console;

use App\Console\Commands\Activity\ActivityAddBonus;
use App\Console\Commands\Activity\ActivityBreaking;
use App\Console\Commands\Activity\ActivityContest;
use App\Console\Commands\Activity\ActivityDailyBet;
use App\Console\Commands\Activity\ActivityDailyDeposit;
use App\Console\Commands\Activity\ActivityRebet;
use App\Console\Commands\Activity\ActivityRegister;
use App\Console\Commands\Activity\CommonActivity;
use App\Console\Commands\Activity\LoadActivityData;
use App\Console\Commands\ActivitySwitch;
use App\Console\Commands\GameApiMaintain;
use App\Console\Commands\HallMaintain;
use App\Console\Commands\ReportData\ReportAgent;
use App\Console\Commands\HallSignInLog;
use App\Console\Commands\SumUserAgent;
use App\Console\Commands\ThirdOrder\HBOrderProcessor;
use App\Console\Commands\ThirdOrder\MWOrderProcessor;
use App\Console\Commands\TransferSupplementProcessor;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use App\Console\Server\Schedule;
use App\Console\Server\CommandDispatch;
use App\Console\Server\SwooleQueue;
use App\Console\Commands\Example;
use App\Console\Commands\SendEmail;
use App\Console\Commands\SendMessage;
use App\Console\Commands\DeleteDemoUser;
use App\Console\Commands\PaymentProcessor;
use App\Console\Commands\ThirdOrder\HCOrderProcessor;
use App\Console\Commands\ThirdOrder\KYOrderProcessor;
use App\Console\Commands\ThirdOrder\LEGOrderProcessor;
use App\Console\Commands\ThirdOrder\SBOrderProcessor;
use App\Console\Commands\ThirdOrder\SBTECHOrderProcessor;
use App\Console\Commands\HallExample;
use App\Console\Commands\ReportData\ReportMoneyLog;
use App\Console\Commands\ReportData\ReportPartnerGame;
use App\Console\Commands\ReportData\ReportPartnerGameThird;
use App\Console\Commands\ThirdOrder\FGOrderProcessor;
use App\Console\Commands\ThirdOrder\SGOrderProcessor;
use App\Console\Commands\ThirdOrder\SGBounsPoolProcessor;
use App\Console\Commands\ThirdOrder\EBETOrderProcessor;
use App\Console\Commands\ThirdOrder\AGOrderProcessor;
use App\Console\Commands\ThirdOrder\BGOrderProcessor;
use App\Console\Commands\ThirdOrder\MGOrderProcessor;
use App\Console\Commands\ThirdOrder\LEBOOrderProcessor;
use App\Console\Commands\BkgeProcesser;
use App\Console\Commands\ThirdOrder\CQ9OrderProcessor;
use App\Console\Commands\ThirdOrder\OGOrderProcessor;
use App\Console\Commands\ThirdOrder\GNSOrderProcessor;
use App\Console\Commands\ThirdOrder\BNGOrderProcessor;
use App\Console\Commands\ThirdOrder\BGTipsProcessor;
use App\Console\Commands\PreBkgeProcesser;
use App\Console\Commands\ClearDayData;
use App\Console\Commands\ThirdOrder\GNSBonusPoolProcesser;
use App\Console\Commands\ThirdOrder\FGBonusPoolProcesser;
use App\Console\Commands\ReportData\ReportOnlineRecharge;
use App\Console\Commands\CheckGame;
use common\enum\QueueEnum;
use App\Console\Commands\CheckHallAPI;


class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        CommandDispatch::class,
        SwooleQueue::class,
        Example::class,
        ReportMoneyLog::class,
        ReportPartnerGame::class,
        ReportPartnerGameThird::class,
        BkgeProcesser::class,
        // order
        FGOrderProcessor::class,
        AGOrderProcessor::class,
        BGOrderProcessor::class,
        MGOrderProcessor::class,
        LEBOOrderProcessor::class,
        SGOrderProcessor::class,
        SGBounsPoolProcessor::class,
        EBETOrderProcessor::class,

        CQ9OrderProcessor::class,
        OGOrderProcessor::class,
        GNSOrderProcessor::class,
        BNGOrderProcessor::class,
        HCOrderProcessor::class,
        KYOrderProcessor::class,
        LEGOrderProcessor::class,
        SBOrderProcessor::class,
        SBTECHOrderProcessor::class,
        HBOrderProcessor::class,
        MWOrderProcessor::class,
        SendMessage::class,
        DeleteDemoUser::class,
        SendEmail::class,
        PaymentProcessor::class,
        ReportAgent::class,
        BGTipsProcessor::class,
        PreBkgeProcesser::class,
        HallSignInLog::class,
        ClearDayData::class,
        //活动,
        ActivityAddBonus::class,
        ActivityDailyBet::class,
        ActivityBreaking::class,
        ActivityContest::class,
        ActivityRebet::class,
        ActivityRegister::class,
        ActivityDailyDeposit::class,
        //gns定时更新奖池
        GNSBonusPoolProcesser::class,
        FGBonusPoolProcesser::class,
        ActivitySwitch::class,//活动开关
        SumUserAgent::class,//统计代理数和会员数

        ReportOnlineRecharge::class,//线上充值报表
        CheckHallAPI::class,
        CheckGame::class,
        HallMaintain::class,
        GameApiMaintain::class,

        //转账异常自动补单
        TransferSupplementProcessor::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \App\Console\Server\Schedule $schedule
     * @return void
     */
    protected function schedule($schedule)
    {

        // ==== 每个厅都需要跑的任务 everyHall hall_id会自动传递到--hall_id参数中，参考HallExample写法=====
        //发送消息（每分钟）
        $schedule->command(Base::PREFIX . 'sendmessage')->everyMinute();
        //72小时自动删除试玩会员（每分钟一次,不用区分厅）
        $schedule->command(Base::PREFIX . 'deleteDemoUser')->everyMinute();
        //发送邮件（每分钟）
        $schedule->command(Base::PREFIX . 'sendemail')->everyMinute()->everyHall();
        //检测admin_log冻结厅主（每30分钟一次）
        $schedule->command(Base::PREFIX . 'hallsigninlog')->everyThirtyMinutes()->everyHall();
        //检测活动开关（每分钟一次）
        $schedule->command(Base::PREFIX . 'activityswitch')->everyMinute()->everyHall();
        //统计代理数和会员数（每分钟一次）
        $schedule->command(Base::PREFIX . 'sumuseragent')->everyMinute()->everyHall();
        //更新游戏API维护状态（每分钟一次）
        $schedule->command(Base::PREFIX . 'gameapimaintain')->everyMinute();
        //更新厅主维护状态（每分钟一次）
        $schedule->command(Base::PREFIX . 'hallmaintain')->everyMinute();

        // 检测游戏标签状态
        $schedule->command(Base::PREFIX . 'check_game --type=tags')->everyFiveMinutes();
        // 检测推荐游戏状态
        $schedule->command(Base::PREFIX . 'check_game --type=recommend')->everyFiveMinutes();

        //计算代理退佣,每天凌晨00:10点跑一次
        $schedule->command(Base::PREFIX . 'handerAgentBkge')->dailyAt("00:10")->everyHall();
        //营销活动，每天凌晨00:00点跑一次数据统计，派奖每分钟确定下是否到发放时间  tid 6,7,8,12  擂台奖 加奖 连续闯关 每日投注
        $schedule->command(Base::PREFIX . 'activity_rebet')->everyMinute()->everyHall();
        $schedule->command(Base::PREFIX . 'activity_add_bonus')->everyMinute()->everyHall();
        $schedule->command(Base::PREFIX . 'activity_breaking')->everyMinute()->everyHall();
        $schedule->command(Base::PREFIX . 'activity_contest')->everyMinute()->everyHall();
        $schedule->command(Base::PREFIX . 'activity_daily_bet')->everyMinute()->everyHall();
        $schedule->command(Base::PREFIX . 'activity_daily_deposit')->everyMinute()->everyHall();
        $schedule->command(Base::PREFIX . 'activity_register')->everyMinute()->everyHall();

        // 检测厅API状态
        $schedule->command(Base::PREFIX . 'check_hall_api')->everyFiveMinutes()->everyHall();

        //计算往期退佣,每1个小时跑一次
        $schedule->command(Base::PREFIX . 'handlePreBkgeData')->hourly()->everyHall();

        //每天凌晨00:00点跑一次(用于自动清零任务,不用区分厅)
        $schedule->command(Base::PREFIX . 'cleardaydata')->dailyAt("00:00");

        // 在线支付订单自定补单, 定时修改支付订单失败 (每分钟)
        $schedule->command(Base::PREFIX . 'payment')->everyMinute();

        // report_online_recharge报表(每小时执行一次)
        $schedule->command(Base::PREFIX . 'report_online_recharge --reload=true --command=today')->hourly();
        // report_online_recharge报表(昨日数据重新执行一次统计)
        $schedule->command(Base::PREFIX . 'report_online_recharge --reload=true --command=yesterday')->dailyAt("00:30");

        // report_partner_game报表 每天0点30分
        $schedule->command(Base::PREFIX . 'report_partner_game --reload=true --command=yesterday')->dailyAt("00:30");
        // report_partner_game报表 每5分钟
        $schedule->command(Base::PREFIX . 'report_partner_game --reload=true --command=today')->everyFiveMinutes();

        // report_partner_game_third 报表 每天0点30分
        $schedule->command(Base::PREFIX . 'report_partner_game_third --reload=true --command=yesterday')->dailyAt("00:30");
        // report_partner_game_third 报表 每5分钟
        $schedule->command(Base::PREFIX . 'report_partner_game_third --reload=true --command=today')->everyFiveMinutes();

        // report_agent报表 每天0点30分
        $schedule->command(Base::PREFIX . 'report_agent --reload=true --command=yesterday')->dailyAt("00:30");
        // report_agent报表  每5分钟
        $schedule->command(Base::PREFIX . 'report_agent --reload=true --command=today')->everyFiveMinutes();

        // report_money_log报表 每5分钟
        $schedule->command(Base::PREFIX . 'report_money_log --reload=true --command=today')->everyFiveMinutes();

        // 转账异常补单 - 5分钟
        $schedule->command(Base::PREFIX . 'transfer_supplement')->everyFiveMinutes();


        //第三方游戲部分, 開發環境不處理, 使用api队列 ============================================================================
        if (env('APP_ENV') == 'dev') {
            return;
        }

        //gns定时更新奖池
        $schedule->command(Base::PREFIX . 'fgBonusPool')->tick(60)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'gnsBonusPool')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'sgUpdateJackpot')->tick(5)->onQueue(QueueEnum::API);

        // 没有测试环境，要在生产环境才跑脚本 ==========================================================================
        if (env('APP_ENV') == 'prod') {
            $schedule->command(Base::PREFIX . 'ag --type=slot')->tick(15)->onQueue(QueueEnum::API);
            $schedule->command(Base::PREFIX . 'ag --type=buyfish')->tick(15)->onQueue(QueueEnum::API);
            $schedule->command(Base::PREFIX . 'ag --type=video')->tick(15)->onQueue(QueueEnum::API);
            $schedule->command(Base::PREFIX . 'ag --type=fish')->tick(15)->onQueue(QueueEnum::API);
            $schedule->command(Base::PREFIX . 'ag --type=yoplay')->tick(15)->onQueue(QueueEnum::API);
        }
        // 拉取注单
        $schedule->command(Base::PREFIX . 'fg')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'bg')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'lebo')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'sg')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'ebet')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'bng')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'hc')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'ky')->tick(10)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'leg')->tick(10)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'sb')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'sbtech')->tick(10)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'hb')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'mw')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'og')->tick(20)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'gns')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'cq9')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'getBgTips')->tick(5)->onQueue(QueueEnum::API);
        $schedule->command(Base::PREFIX . 'mg')->tick(15)->onQueue(QueueEnum::API);

    }

    /**
     * Define the application's command schedule.
     *
     * @return void
     */
    protected function defineConsoleSchedule()
    {
        $this->app->instance(
            'Illuminate\Console\Scheduling\Schedule',
            $schedule = new Schedule($this->app)
        );

        $this->schedule($schedule);
        $schedule->parseTickEvents();
    }
}
